/*
* 报表数据解析引擎
* */
import {deepFullCopy, messages, formatNumber} from "share/common";
import {_ts, lengthStrShow} from "containers/data-center/report/report-utils";
export default {
  optionExample: {
    title: {
      text: '---',//初始化数据时设置
      left: 'center',
      textStyle: {
        fontWeight: 'bold'
      }
    },
    tooltip : {
      trigger: 'axis',
      axisPointer : {            // 坐标轴指示器，坐标轴触发有效
        type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
      }
    },
    grid: {
      left: '3%',
      right: '10%',
      bottom: '3%',
      containLabel: true
    },
    xAxis : [
      {
        type : 'category',
        data : [],
        axisTick: {
          alignWithLabel: true
        },
        axisLabel: {
          rotate: 45,
          margin: 10,
          textStyle: {
            fontWeight: "bolder",
            color: "#000000"
          }
        },
      }
    ],
    yAxis : [
      {
        type : 'value',
        name: messages('data-center.key133')/*金额（元）*/
      }
    ],
    series : [
      {
        type:'bar',
        barWidth: 24,
        data:[]
      }
    ]
  },
  //费用 top10
  feeExpenseReport(_data) {
    let data = _data;
    //最多只要显示 10 个
    if(_data.length > 10){
      data = _data.splice(0,10);
    }
    let options = deepFullCopy(this.optionExample);
    options.title.text = messages('data-center.key134')/*费用-累计超标金额TOP10*/;
    let xAxisData = [], baseAmountArr = [];
    data.map(item => {
      xAxisData.push(_ts(item.ruleExpenseTypeNames));
      let d = {
        value: parseFloat(item.excessAmount).toFixed(2),
        ruleExpenseTypeNames: item.ruleExpenseTypeNames,
      };
      baseAmountArr.push(d);
    });
    options.xAxis[0].data = xAxisData;
    options.xAxis[0].name = messages('common.expense.type')/*费用类型*/;
    options.series[0].data = baseAmountArr;

    options.tooltip.formatter = function (datas) {
      let res = lengthStrShow(datas[0].data.ruleExpenseTypeNames) + ":</br>", val;
      for (let i = 0, length = datas.length; i < length; i++) {
        val = datas[i].value ? formatNumber(datas[i].value) : "";
        res += val;
      }
      return res;
    };
    return options;
  },
  //人员 top10
  personExpenseReport(_data) {
    let data = _data;
    //最多只要显示 10 个
    if(_data.length > 10){
      data = _data.splice(0,10);
    }
    let options = deepFullCopy(this.optionExample);
    options.title.text = messages('data-center.key135')/*人员-累计超标金额TOP10*/;
    let xAxisData = [], baseAmountArr = [];
    data.map(item => {
      xAxisData.push(_ts(item.expenseOwnerName));
      let d = {
        value: parseFloat(item.excessAmount).toFixed(2),
        expenseOwnerName: item.expenseOwnerName,
      };
      baseAmountArr.push(d);
    });
    options.xAxis[0].data = xAxisData;
    options.xAxis[0].name = messages('data-center.key131')/*人员*/;
    options.series[0].data = baseAmountArr;
    options.tooltip.formatter = function (datas) {
      let res = lengthStrShow(datas[0].data.expenseOwnerName) + ":</br>", val;
      for (let i = 0, length = datas.length; i < length; i++) {
        val = datas[i].value ? formatNumber(datas[i].value) : "";
        res += val;
      }
      return res;
    };
    return options;
    return options;
  },
}
